package com.tssf.car_manage.controller;

import com.tssf.car_manage.entity.Locations;
import com.tssf.car_manage.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

@Controller
@RequestMapping("/location")
public class LocationController {
    @Autowired
    LocationService locationService;

    // 获取位置
    @GetMapping("/getLocation")
    public String getLocation(Model model) {
        Locations locations = locationService.selectLocation();
        model.addAttribute("location", locations);
        return "positioning";
    }

    // 保存位置
    @PostMapping("/saveLocation")
    public String saveLocation(@RequestBody Locations location) {
        locationService.upsertLocation(location);
        return "redirect:/location/getLocation";
    }
    //页面跳转（定位）
    @GetMapping("/positioning")
    public String positioning(){
        return "positioning";
    }
}
